$(document).ready(function(){

//	Creat Table for Horizontal Fuild Layout
	var userAgent = navigator.userAgent.toLowerCase();
	jQuery.browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		safari: /webkit/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
	};
	if($.browser.msie){
		$("#hwrapper").wrapInner(document.createElement("tr"));
		$("#hwrapper").wrapInner(document.createElement("table"));
		$(".hcol").wrap("<td>");
	} else {
		$("#hwrapper").wrapInner("<table><tr>");
		$(".hcol").wrap("<td>");
	};
	$("#hwrapper > table").addClass('htable');
	$(".hcol").css({'display':'block'});
	
	$('.timeline').mousedown(function (event) {
            $(this)
                .data('down', true)
                .data('x', event.clientX)
                .data('scrollLeft', this.scrollLeft);
                
            return false;
        }).mouseup(function (event) {
            $(this).data('down', false);
        }).mousemove(function (event) {
            if ($(this).data('down') == true) {
                this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
            }
        }).mousewheel(function (event, delta) {
            this.scrollLeft -= (delta * 30);
        }).css({
            'overflow' : 'hidden',
            'cursor' : 'move'
        });
	
// TAB	
	$('#htabtitle ul li').click(function(){ 
		$(this).addClass('selected');
		$(this).siblings("#htabtitle ul li").removeClass('selected');
		$('#htabmain').animate({left:-632*$('#htabtitle ul li').index(this)+"px"},500);
	});
	
	$('#stabtitle ul li').click(function(){ 
		$(this).addClass('selected');
		$(this).siblings("#stabtitle ul li").removeClass('selected');
		$('#stabmain').animate({left:-786*$('#stabtitle ul li').index(this)+"px"},500);
	});
	
// Slider
	$(".hstore-1 .slider").easySlider({
		auto:false,
		continuous: true,
		numeric: true,
		prevNext: true,
		prevId: 'store-prevBtn-1',
        nextId: 'store-nextBtn-1',
		numericId: 'store-controls-1'
	});
	
	$(".hstore-2 .slider").easySlider({
		auto:false,
		continuous: true,
		numeric: true,
		prevNext: true,
		prevId: 'store-prevBtn-2',
        nextId: 'store-nextBtn-2',
		numericId: 'store-controls-2'
	});
	
	$(".hads .accordion").hrzAccordion({
		containerClass: 'slider',
		openOnLoad: "1",
		handlePosition: 'left',
		fixedWidth : 482,
		cycle: true,
		cycleInterval: 3000
	});
	
	$(".hmonth ul li a").each(function() {
		var hrefId = $(this).next().children(".popbox").attr("id");
		// $(this).prepend('0'+hrefId+'1');
		$(this).colorbox({
			width:"550px", 
			maxHeight: "400px",
			inline:true, 
			href:"#"+hrefId,
			current: " {current} / {total}"
		});
	})
	
	$("#hcatnav").css("position", "absolute");
	
	var hw = $("#hwrapper > .htable").outerWidth();
	$("#hwrapper").width(hw).css({"overflow":"hidden"});
	
	$('#hwrapper a').attr({target: "_blank"});
	$('.havatars a,.name a,.htags a, .hfilter_sr a, .meta-cat a, .hstore .more a, .hnav a').removeAttr("target");
	
});

$(window).mouseout(function (event) {
        if ($('.timeline').data('down')) {
            try {
                if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
                    $('.timeline').data('down', false);
                }                
            } catch (e) {}
        }
  });
  
$(window).scroll(function() {
	var hw = $("#hwrapper > .htable").outerWidth();
	var sw = $(window).scrollLeft();
	if(sw > hw) {
		$("#hcatnav").css("left", "0px");
	} else {
		$("#hcatnav").css("left", sw + "px");
	}
})